<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\model;

use think\Db;

/**
 * 分站承检车型
 * Class VehicleInspectionCompany
 * @package app\api\model
 */
class VehicleInspectionCompany extends BaseModel
{
    /**
     * @Desc 追加title字段
     *
     * @param $value
     * @param $data
     *
     * @return bool|float|mixed|string|null
     */
    protected function getTitleAttr($value, $data)
    {
        return Db::name('vehicle')->where('id', '=', $data['license_type'])->value('title');
    }

    /**
     * @Desc 获取检车项目
     *
     * @param int    $company_id  检车站ID
     * @param string $vehicle_ids 检车站的检车类型
     *
     * @return mixed
     */
    public static function getInspectionList($company_id, $vehicle_ids)
    {
        $field = 'id, inspection_id as goods_id, goods_name, shop_price, license_type';
        $where = [
            'company_id' => $company_id,
            'is_use'     => 1,
        ];
        $vehicle_ids && $where['license_type'] = ['in', $vehicle_ids];
        $list = (new self)->field($field)->where($where)->order('sort')->select();
        return $list->append(['title'])->toArray();
    }

    /**
     * @Desc 根据车型获取检车项目
     *
     * @param array $param
     *
     * @return bool|false|\PDOStatement|string|\think\Collection
     */
    public static function getListByType(array $param)
    {
        $field = 'inspection_id as goods_id, goods_name, shop_price';
        return (new self)->field($field)->where('license_type', '=', $param['license_type'])->where('company_id', '=', $param['company_id'])->where('is_use', '=', 1)->order('sort')->select();
    }
}